package cn.kooki.app.duobao.ui.Activity.Comm;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.autoupdatesdk.BDAutoUpdateSDK;
import com.bumptech.glide.Glide;
import com.iapppay.sdk.main.IAppPay;
import com.qihoo.appstore.updatelib.UpdateManager;
import com.umeng.socialize.PlatformConfig;
import com.umeng.update.UmengUpdateAgent;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.BuildConfig;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseActivity;
import cn.kooki.app.duobao.core.MainFactory;
import cn.kooki.app.duobao.data.Bean.User.LoginType;
import cn.kooki.app.duobao.data.Bean.base.BaseResponse;
import cn.kooki.app.duobao.data.constant.Constants;
import cn.kooki.app.duobao.util.SharePreferencesUtils;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by xiong on 2015/11/25.
 */
public class LanunchActivity extends BaseActivity {
    @Bind(R.id.launcher_ad)
    ImageView launcherAd;
    @Bind(R.id.launcher_logo)
    ImageView launcherLogo;
    @Bind(R.id.launch_copyright)
    TextView launchCopyright;
    @Bind(R.id.root)
    RelativeLayout root;

    @Override
    protected void setToolbar() {

    }

    private Handler handler = new Handler();

    @Override
    protected void setLayoutContentView() {
        setContentView(R.layout.activity_launch);
        ButterKnife.bind(this);
    }

    @Override
    protected void afterView() {
        getloginType();
        IAppPay.init (this,IAppPay.PORTRAIT,Constants.IPAY_APP_ID);
        Glide.with(this).load(Constants.luanch_url).override(800, 1280).crossFade(500).into(launcherAd);
    }

    private void goIndex(){
        final int type = getIntent().getIntExtra("type", -1);
        final String title =  getIntent().getStringExtra("title");
        final String text =  getIntent().getStringExtra("text");
        final String username =  getIntent().getStringExtra("username");
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Bundle bundle = new Bundle();
                if (type != -1){
                    bundle.putString("title",title);
                    bundle.putInt("type",type);
                    bundle.putString("text",text);
                    bundle.putString("username",username);
                }
                Intent intent = new Intent(LanunchActivity.this,RootAcitivity.class);
                startActivity(intent);
                finish();
            }
        }, 1500);
    }

    private void getloginType() {
        MainFactory.getApiInstance().getlogintype(new Callback<LoginType>() {
            @Override
            public void success(LoginType loginType, Response response) {
                if (loginType.data!=null){
                    SharePreferencesUtils.putInt(LanunchActivity.this,LoginType.LOING,loginType.data.login);
                }
                goIndex();
            }

            @Override
            public void failure(RetrofitError error) {
                goIndex();
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Glide.get(getApplicationContext()).clearMemory();
    }


}
